//
//  RmtpManage.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/2/27.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "RtmpManage.h"
#import "RandVideoModel.h"
@implementation RtmpManage
-(void)update_live
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"live_api" A:@"update_live"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    //[param setObject:@"" forKey:@""];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if([self.delegate respondsToSelector:@selector(updateRtmp:)])
        {
            updateLiveModel *model = [updateLiveModel modelWithJSON:responseObject];
            [self.delegate updateRtmp:model];
            
            self.timer = [NSTimer timerWithTimeInterval:20 target:self selector:@selector(heartbeat) userInfo:nil repeats:YES];
            [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
            
        }
    
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
}

-(void)removetime
{
    [_timer invalidate];
    _timer = nil;
}

//获取随机的视屏
-(void)getvideo
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"live_api" A:@"rand_video_live_list"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@"2" forKey:@"count"];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if([self.delegate respondsToSelector:@selector(updateRandVideo:)])
        {
            RandVideoModel *model = [RandVideoModel modelWithJSON:responseObject];
            [self.delegate updateRandVideo:model];
        }
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
}

-(void)getonlineUser
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"page_data_api" A:@"get_online_user"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObject:@"3" forKey:@"count"];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        if([self.delegate respondsToSelector:@selector(updateRandVideo:)])
        {
            RandVideoModel *model = [RandVideoModel modelWithJSON:responseObject];
            [self.delegate updateRandVideo:model];
        }
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
}

-(void)heartbeat
{
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"live_api" A:@"update_live"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    //[param setObject:@"" forKey:@""];
    
    [CYNET POSTv2:url parameters:param responseCache:^(id responseObject) {
        
    } success:^(id responseObject) {
        NSLog(ASLocalizedString(@"视频聊心跳===="));
        
    } failure:^(NSString *error) {
        [MBProgressHUD showTopTipMessage:error];
    } hasCache:NO];
    
    //通知视频
//    [self getvideo];
}
@end
